package com.sx.manage.controller.consumer.person;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sx.manage.controller.base.MBaseController;
import com.sx.manage.service.consumer.MConsumerWebServiceImpl;
import com.sx.manage.service.consumer.referee.RefereeWebServiceImpl;
import com.sx.model.manage.mybatis.form.consumer.MPersonalConsumerNetworkForm;
import com.sx.model.manage.mybatis.vo.consumer.MVerifOpenAccountVO;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultVerifyVO;

/**
 * provider 需要代用的 controller
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/provider")
public class MProviderController extends MBaseController {
	// 日志
	private Logger log = LoggerFactory.getLogger(this.getClass());
	@Resource
	private MConsumerWebServiceImpl consumerWebServiceImpl;
	@Resource
	private RefereeWebServiceImpl refereeWebServiceImpl;

	/**
	 * 子账户开户（华夏二代接口开户）
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping(value = "openConsumerAccountsHuaxia02/openAccountsNoCard", produces = "application/json; charset=utf-8")
	@ResponseBody
	public ResultVerifyVO<MVerifOpenAccountVO> openAccountsNoCard(@RequestBody MPersonalConsumerNetworkForm form) {
		log.debug(" MPersonConsumerInfoController   方法   openAccountsNoCard 调用");
		ResultVerifyVO<MVerifOpenAccountVO> result = consumerWebServiceImpl.openAccountsNoCard(new Long[] { form.getConsumer_id() });
		if (!result.isSuccess()) {
			log.info("注册用户开户失败error={}", result.getMsg());
			return result;
		}
		ResultBooleanVO registerReceiveResult = refereeWebServiceImpl.registerReceive(form.getConsumer_id());
		if (!registerReceiveResult.isSuccess()) {
			log.info("error={}", registerReceiveResult.getMsg());
			ResultVerifyVO<MVerifOpenAccountVO> returnResult = new ResultVerifyVO<>(false, null, "开户成功," + registerReceiveResult.getMsg());
			if ("11058".equals(registerReceiveResult.getMsgcode())) {
				returnResult.setSuccess(true);
			}
			log.info("returnResult={}", returnResult);
			return returnResult;
		}
		return result;
	}

	/**
	 * 注册成功后领取奖励
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping(value = "openConsumerAccountsHuaxia02/registerReceive", produces = "application/json; charset=utf-8")
	@ResponseBody
	public ResultBooleanVO registerReceive(@RequestBody MPersonalConsumerNetworkForm form) {
		log.debug(" MPersonConsumerInfoController   方法   openAccountsNoCard 调用");
		return refereeWebServiceImpl.registerReceive(form.getConsumer_id());
	}

}
